#include "obj_recog.h"
#include "obj_recog_classifier.h"

#include <iostream>

namespace jf_obj_recog {

typedef struct
{
	Classifier *classifier;
}global_data;


int object_recognition_init(HANDLE *pHandle, const string model_file, const string trained_file, const string mean_file, const vector<string> label_files, int GPUID)
{

	if (!pHandle || !model_file.c_str() || !trained_file.c_str() || !mean_file.c_str() || label_files.size() < 0)
	{
		return -1;
	}
		
	*pHandle = NULL;

	global_data * pGlobalData = (global_data *)malloc(sizeof(global_data));

	if (!pGlobalData)
		return -2;

	pGlobalData->classifier = new Classifier(model_file, trained_file, mean_file, label_files, GPUID);

	*pHandle = (HANDLE)pGlobalData;

	return 0;
}
int object_recognition_process(HANDLE handle, cv::Mat img, std::vector<vector<Prediction> >& predict)
{
	if (NULL == handle || NULL == img.data)
		return -1;


	global_data * pGlobalData = (global_data *)handle;
	predict = pGlobalData->classifier->Classify(img);

	return 0;

}
int object_recognition_destory(HANDLE handle)
{
	if (NULL == handle)
		return -1;

	global_data * pGlobalData = (global_data *)handle;
	if (pGlobalData != NULL)
	{
		if (pGlobalData->classifier != NULL)
			delete pGlobalData->classifier;
		free(pGlobalData);
	}
	return 0;
}

}
